import { AuthService } from '../auth/service'

document.addEventListener('DOMContentLoaded', function () {
  const backButton = document.querySelector('.back-button')
  const googleButton = document.querySelector('.google-button')
  const checkboxes = document.querySelectorAll('.checkbox-input')

  // Back button handler
  backButton?.addEventListener('click', function () {
    window.history.back()
  })

  // Google login button handler
  googleButton?.addEventListener('click', async function () {
    // Check if terms checkbox is checked
    const termsAccepted = (document.getElementById('terms') as HTMLInputElement).checked

    if (!termsAccepted) {
      alert('Please accept the Terms & Conditions to continue')
      return
    }

    // 谷歌登录
    try {
      const authUrl = await AuthService.getGoogleAuthUrl('yourVocabulary')
      authUrl && (window.location.href = authUrl)
    } catch (error) {
      // 提示重试
      console.error('Error initiating Google auth:', error)
    }
  })
})
